package com.glory.brepda.activity.mfg;


import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.n2CabinetEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.OnClick;

public class EapOperationActivity extends BaseActivity {
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvEqpId)
    FreeUI_ClearEditText tvEqpId;
    @BindView(R.id.tvTechnician)
    FreeUI_ClearEditText tvTechnician;
    @BindView(R.id.tvOperators)
    FreeUI_ClearEditText tvOperators;




    @Override
    protected int getLayoutResId() {
        return R.layout.activity_eap_operation;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        tvTitle.setText("三分厂稼动率登录");
        tvBaseSubmit.setText("提交");
        tvEqpId.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                // 在文本改变后调用
                if (s.length() > 0 && s.charAt(s.length() - 1) != ';') {
                    s.append(";");

                }

            }
        });
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
//                if (actionControl("DownLoad04"))
//                    return;

                if (getText(tvEqpId).equals("") ) {
                    showToast("设备号不能为空", false);
                    return;
                }
//                if (getText(tvTechnician).equals("") ) {
//                    showToast("技术员不能为空", false);
//                    return;
//                }
//                if (getText(tvOperators).equals("") ) {
//                    showToast("操作工不能为空", false);
//                    return;
//                }
                submit();
                break;

        }
    }

    private void submit() {
        FreeUI_EntityCallBack<BaseResponseBean<JSONObject>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<JSONObject>>
                (new TypeToken<BaseResponseBean<JSONObject>>() {
                }.getType(), getSupportFragmentManager(), this) {

            @Override
            public void onSuccess(Response<BaseResponseBean<JSONObject>> response) {
                super.onSuccess(response);
                showToast("提交成功",true);
            }

            @Override
            public void onError(Response<BaseResponseBean<JSONObject>> response) {
                super.onError(response);
                loadError(response.getException(), "JDLLOGIN");
            }
        };

        JsonObject map = new JsonObject();
        map.addProperty("EQPSID",getText(tvEqpId));
        map.addProperty("OPERATORS",getText(tvOperators));
        map.addProperty("TECHNICIAN",getText(tvTechnician));
        NetUtils.requestPostNet("IF.JDLLOGIN","JDLLOGIN", EapOperationActivity.this,map,callBack);
    }
}
